-- 武器类
local Object = require("app.mode.Object")

local Weapon = {}
Weapon.__index = Weapon
setmetatable(Weapon, Object)

local sfc = cc.SpriteFrameCache:getInstance()

function Weapon:initView()
    self._sprite = cc.Sprite:createWithSpriteFrame(sfc:getSpriteFrameByName(self:getName() .. ".png"))
end

function Weapon:exportData()
    local data = Object.exportData(self)
    data.x, data.y = self:getPosition()
    return data
end

function Weapon:die()
    -- 从场景中移除
    self._scene:removeWeapon(self)

    local animation = cc.Animation:create()
    animation:setDelayPerUnit(0.1)
    animation:setLoops(1)
    animation:addSpriteFrame(self:getSprite():getSpriteFrame())
    animation:addSpriteFrame(sfc:getSpriteFrameByName(self:getName() .. "_die.png"))

    local animate = cc.Animate:create(animation)

    self._sprite:runAction(
        cc.Sequence:create(
            animate,
            cc.CallFunc:create(
                function(node, data)
                    self:removeSelf()
                end
            ),
            nil
        )
    )
end

function Weapon:getEffect()
    return self._data.effect
end

return Weapon
